import React from 'react';
import {Form, InputNumber as Number} from "antd";
import BaseEntity from "../../type/entity";
interface IProps<T> {
    name: keyof T,
    label?: string,
    required?: boolean,
    /**
     * 数值前缀
     */
    before?: React.ReactNode,
    /**
     * 数值后缀
     */
    after?: React.ReactNode,
    max?: number,
    /**
     * 数值精度,小数点后几位
     */
    precision?: number

}
const InputNumber = <T extends BaseEntity>(props: IProps<T>) => {
    return (
        <Form.Item<T>
            name={props.name as any}
            label={props.label}
            required={props.required}
            rules={[{required: props.required, message: `${props.label}不能为空!`}]}
        >
            <Number
                style={{width: "150px"}}
                min={0}
                max={props.max ?? 99}
                placeholder={`请输入${props.label}`}
                addonBefore={props.before}
                addonAfter={props.after}
                precision={props.precision}
            />
        </Form.Item>
    );
};

export default InputNumber;